#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define BUFSIZE 1024


int main(int argc,char **argv)
{

		int sfd,dfd;
		int len, red;
		char buf[BUFSIZE];
		if(argc<2){
				fprintf(stderr,"Usage......\n");
				exit(1);
		}		




		sfd  =	open(argv[1],O_RDONLY);
		if(sfd < 0)
		{

				perror("open()");
				exit(1);
		}

		dfd = open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0600);
		if(dfd < 0)
		{

				close(sfd);
				perror("open()");
				exit(1);
		}

		while(1)
		{
				len = read(sfd,buf,BUFSIZE);
				if(len < 0){
						perror("read()");
						break;
				}	
				if(len == 0){
						break;
				}	

				red = write(dfd,buf,len);
				if (red < 0)
				{

						perror("write()");
						break;	
				}


		}


		close(sfd);
		close(dfd);

		exit(0);
}
